<?php
session_start();
require_once('config.php');
require_once('blocks/user_quyen.php');

if($_POST['view_wall_all']=='view_wall_all'){
	$user = $_POST['user'];
	$page = $_POST['page'];
	$from = (($page-1)*max_wall);
	
	$wall_insert_friend = $tc->friends($idUser);
	$wall_insert_friend = explode($user,$wall_insert_friend);
	
	if(($user==$idUser || count($wall_insert_friend)==2) && $page==1) $view_wall = '<script>$(document).ready(function() {if(navigator.appName!="Microsoft Internet Explorer"){$(".info, .comment").corner("top 5px");	$("#status").corner("5px");	}});</script>'.$wall_status;
	$wall_info = $tc->view_wall_info($user,$from);
	$total_wall = mysql_num_rows($wall_info);
	if($total_wall==0 && $page>1) $view_wall='0';
	else{
		while($row_wall_info = mysql_fetch_array($wall_info)){
			if($row_wall_info['share_id']==1){
				$date = $tc->wall_datetime($row_wall_info['date_create']);
				$user_id = explode(',',$row_wall_info['user_id']);
				$user_id = $tc->user_info($user_id[0]);
				$row_user_id = mysql_fetch_array($user_id);
				$photo_name = explode(',',$row_wall_info['photo_name']);
				$total = count($photo_name);
				$j=0; $photo_view = '';
				if($total==2){
					$photo_view .= $tc->view_photo(476,320,$photo_name[$j]);
				}elseif($total==3){
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]);
				}elseif($total==4){
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]);
				}elseif($total==5){
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]);
				}elseif($total>5){
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]);
				}
				(($tc->check_like($row_wall_info['id'],$idUser))==0) ? $like='Thích' : $like='Bỏ thích';
				$total_like = count(explode(' || ',$row_wall_info['user_like']))-1;
				($total_like != 0) ? $total_like='Có '.$total_like.' người thích đều này' : $total_like='';
				if($user==$idUser) $delete='<div class="info infodelete'.$row_wall_info['id'].'"><div class="delete delete'.$row_wall_info['id'].'">x</div>'; else $delete='<div class="info">';
				$view_wall .= $delete.'
					<div class="title">
						<div class="icon"><a href="'.$row_user_id['id'].'/"><img src="'.url_hinh_user_40x40.$row_user_id['avatar'].'.jpg" alt="" /></a></div>
						<div class="name"><a href="'.$row_user_id['id'].'/">'.$row_user_id['name'].'</a></div>
						<div class="date">'.$date.' <a href="#" id="share"><img style="padding:0 5px" src="images/public_icon.jpg" alt="share" /></a></div>
					</div>
					<div class="content">'.$row_wall_info['content'].'</div>
					<div class="view_photo">'.$photo_view.'<div style="clear:both; height:1px"></div></div>
					<div class="action"><a href="javascript:;" class="like like_'.$row_wall_info['id'].'">'.$like.'</a> &nbsp; <a href="javascript:;" class="binhluan '.$row_wall_info['id'].'">Bình luận</a><span style="color:#999; padding-left:10px">'.$total_like.'</span></div>
				';
				$comment = $tc->view_comment($row_wall_info['id']); 
				if(mysql_num_rows($comment)==1){
					$row_comment = mysql_fetch_array($comment);
					$m_comment = explode(' |-| ',$row_comment['comment']);
					$m_user_id = explode(' |-| ',$row_comment['user_id']);
					$m_date_create = explode(' |-| ',$row_comment['date_create']);
					$view_wall .= '<div id="ajax_wall_cm'.$row_wall_info['id'].'"></div>';
					for($i=count($m_comment)-1; $i>0; $i--){
						$user_comment = $tc->user_info($m_user_id[$i]);
						$user_comment = mysql_fetch_array($user_comment);
						$view_wall .= '<div class="comment"><div class="comment_img"><a href="'.$m_user_id[$i].'/"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt=""></a></div><div class="comment_cm"><a href="'.$m_user_id[$i].'/"><strong>'.$user_comment['name'].'</strong></a> '.$m_comment[$i].'<div class="date">'.$tc->wall_datetime($m_date_create[$i]).'</div></div><div style="clear:both; height:1px"></div></div>';
					}
				}
				if(@$idUser) $wall_comment = '<div class="show_cm show_cm'.$row_wall_info['id'].'"><div class="comment"><div class="comment_img"><a href="#"><img src="'.$avatar.'" alt=""> </a></div><div class="comment_cm"><input type="text" name="comment" value="" id="comment'.$row_wall_info['id'].'" class="frmcomment" /></div><div style="clear:both; height:1px"></div></div></div>';
				$view_wall .= $wall_comment.'</div>';
			}elseif($row_wall_info['user_id']==$idUser){
				$date = $tc->wall_datetime($row_wall_info['date_create']);
				$user_id = explode(',',$row_wall_info['user_id']);
				$user_id = $tc->user_info($user_id[0]);
				$row_user_id = mysql_fetch_array($user_id);
				$photo_name = explode(',',$row_wall_info['photo_name']);
				$total = count($photo_name);
				$j=0; $photo_view = '';
				if($total==2){
					$photo_view .= $tc->view_photo(476,320,$photo_name[$j]);
				}elseif($total==3){
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]);
				}elseif($total==4){
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]);
				}elseif($total==5){
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]);
				}elseif($total>5){
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]);
				}
				(($tc->check_like($row_wall_info['id'],$idUser))==0) ? $like='Thích' : $like='Bỏ thích';
				$total_like = count(explode(' || ',$row_wall_info['user_like']))-1;
				($total_like != 0) ? $total_like='Có '.$total_like.' người thích đều này' : $total_like='';
				if($user==$idUser) $delete='<div class="info infodelete'.$row_wall_info['id'].'"><div class="delete delete'.$row_wall_info['id'].'">x</div>'; else $delete='<div class="info">';
				$view_wall .= $delete.'
					<div class="title">
						<div class="icon"><a href="'.$row_user_id['id'].'/"><img src="'.url_hinh_user_40x40.$row_user_id['avatar'].'.jpg" alt="" /></a></div>
						<div class="name"><a href="'.$row_user_id['id'].'/">'.$row_user_id['name'].'</a></div>
						<div class="date">'.$date.' <a href="#" id="share"><img style="padding:0 5px" src="images/public_icon.jpg" alt="share" /></a></div>
					</div>
					<div class="content">'.$row_wall_info['content'].'</div>
					<div class="view_photo">'.$photo_view.'<div style="clear:both; height:1px"></div></div>
					<div class="action"><a href="javascript:;" class="like like_'.$row_wall_info['id'].'">'.$like.'</a> &nbsp; <a href="javascript:;" class="binhluan '.$row_wall_info['id'].'">Bình luận</a><span style="color:#999; padding-left:10px">'.$total_like.'</span></div>
				';
				$comment = $tc->view_comment($row_wall_info['id']); 
				if(mysql_num_rows($comment)==1){
					$row_comment = mysql_fetch_array($comment);
					$m_comment = explode(' |-| ',$row_comment['comment']);
					$m_user_id = explode(' |-| ',$row_comment['user_id']);
					$m_date_create = explode(' |-| ',$row_comment['date_create']);
					$view_wall .= '<div id="ajax_wall_cm'.$row_wall_info['id'].'"></div>';
					for($i=count($m_comment)-1; $i>0; $i--){
						$user_comment = $tc->user_info($m_user_id[$i]);
						$user_comment = mysql_fetch_array($user_comment);
						$view_wall .= '<div class="comment"><div class="comment_img"><a href="'.$m_user_id[$i].'/"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt=""></a></div><div class="comment_cm"><a href="'.$m_user_id[$i].'/"><strong>'.$user_comment['name'].'</strong></a> '.$m_comment[$i].'<div class="date">'.$tc->wall_datetime($m_date_create[$i]).'</div></div><div style="clear:both; height:1px"></div></div>';
					}
				}
				if(@$idUser) $wall_comment = '<div class="show_cm show_cm'.$row_wall_info['id'].'"><div class="comment"><div class="comment_img"><a href="#"><img src="'.$avatar.'" alt=""> </a></div><div class="comment_cm"><input type="text" name="comment" value="" id="comment'.$row_wall_info['id'].'" class="frmcomment" /></div><div style="clear:both; height:1px"></div></div></div>';
				$view_wall .= $wall_comment.'</div>';
			}
		}
		mysql_free_result($wall_info);
	}
	echo $view_wall;
}

if($_POST['view_wall_one']=='view_wall_one'){
	$user = $_POST['user'];
	$info_id = $_POST['info_id'];
	
	$wall_info = $tc->view_wall_info_one($user,$info_id);
	$total_wall = mysql_num_rows($wall_info);
	if($total_wall==0) $view_wall='';
	else{
		while($row_wall_info = mysql_fetch_array($wall_info)){
			if($row_wall_info['share_id']==1){
				$date = $tc->wall_datetime($row_wall_info['date_create']);
				$user_id = explode(',',$row_wall_info['user_id']);
				$user_id = $tc->user_info($user_id[0]);
				$row_user_id = mysql_fetch_array($user_id);
				$photo_name = explode(',',$row_wall_info['photo_name']);
				$total = count($photo_name);
				$j=0; $photo_view = '';
				if($total==2){
					$photo_view .= $tc->view_photo(476,320,$photo_name[$j]);
				}elseif($total==3){
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]);
				}elseif($total==4){
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]);
				}elseif($total==5){
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]);
				}elseif($total>5){
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]);
				}
				(($tc->check_like($row_wall_info['id'],$idUser))==0) ? $like='Thích' : $like='Bỏ thích';
				$total_like = count(explode(' || ',$row_wall_info['user_like']))-1;
				($total_like != 0) ? $total_like='Có '.$total_like.' người thích đều này' : $total_like='';
				if($user==$idUser) $delete='<div class="info infodelete'.$row_wall_info['id'].'"><div class="delete delete'.$row_wall_info['id'].'">x</div>'; else $delete='<div class="info">';
				$view_wall .= $delete.'
					<div class="title">
						<div class="icon"><a href="'.$row_user_id['id'].'/"><img src="'.url_hinh_user_40x40.$row_user_id['avatar'].'.jpg" alt="" /></a></div>
						<div class="name"><a href="'.$row_user_id['id'].'/">'.$row_user_id['name'].'</a></div>
						<div class="date">'.$date.' <a href="#" id="share"><img style="padding:0 5px" src="images/public_icon.jpg" alt="share" /></a></div>
					</div>
					<div class="content">'.$row_wall_info['content'].'</div>
					<div class="view_photo">'.$photo_view.'<div style="clear:both; height:1px"></div></div>
					<div class="action"><a href="javascript:;" class="like like_'.$row_wall_info['id'].'">'.$like.'</a> &nbsp; <a href="javascript:;" class="binhluan '.$row_wall_info['id'].'">Bình luận</a><span style="color:#999; padding-left:10px">'.$total_like.'</span></div>
				';
				$comment = $tc->view_comment($row_wall_info['id']); 
				if(mysql_num_rows($comment)==1){
					$row_comment = mysql_fetch_array($comment);
					$m_comment = explode(' |-| ',$row_comment['comment']);
					$m_user_id = explode(' |-| ',$row_comment['user_id']);
					$m_date_create = explode(' |-| ',$row_comment['date_create']);
					$view_wall .= '<div id="ajax_wall_cm'.$row_wall_info['id'].'"></div>';
					for($i=count($m_comment)-1; $i>0; $i--){
						$user_comment = $tc->user_info($m_user_id[$i]);
						$user_comment = mysql_fetch_array($user_comment);
						$view_wall .= '<div class="comment"><div class="comment_img"><a href="'.$m_user_id[$i].'/"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt=""></a></div><div class="comment_cm"><a href="'.$m_user_id[$i].'/"><strong>'.$user_comment['name'].'</strong></a> '.$m_comment[$i].'<div class="date">'.$tc->wall_datetime($m_date_create[$i]).'</div></div><div style="clear:both; height:1px"></div></div>';
					}
				}
				if(@$idUser) $wall_comment = '<div class="show_cm show_cm'.$row_wall_info['id'].'"><div class="comment"><div class="comment_img"><a href="#"><img src="'.$avatar.'" alt=""> </a></div><div class="comment_cm"><input type="text" name="comment" value="" id="comment'.$row_wall_info['id'].'" class="frmcomment" /></div><div style="clear:both; height:1px"></div></div></div>';
				$view_wall .= $wall_comment.'</div>';
			}elseif($row_wall_info['user_id']==$idUser){
				$date = $tc->wall_datetime($row_wall_info['date_create']);
				$user_id = explode(',',$row_wall_info['user_id']);
				$user_id = $tc->user_info($user_id[0]);
				$row_user_id = mysql_fetch_array($user_id);
				$photo_name = explode(',',$row_wall_info['photo_name']);
				$total = count($photo_name);
				$j=0; $photo_view = '';
				if($total==2){
					$photo_view .= $tc->view_photo(476,320,$photo_name[$j]);
				}elseif($total==3){
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(237,158,$photo_name[$j]);
				}elseif($total==4){
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(156,104,$photo_name[$j]);
				}elseif($total==5){
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(115,80,$photo_name[$j]);
				}elseif($total>5){
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]); $j++;
					$photo_view .= $tc->view_photo(92,61,$photo_name[$j]);
				}
				(($tc->check_like($row_wall_info['id'],$idUser))==0) ? $like='Thích' : $like='Bỏ thích';
				$total_like = count(explode(' || ',$row_wall_info['user_like']))-1;
				($total_like != 0) ? $total_like='Có '.$total_like.' người thích đều này' : $total_like='';
				if($user==$idUser) $delete='<div class="info infodelete'.$row_wall_info['id'].'"><div class="delete delete'.$row_wall_info['id'].'">x</div>'; else $delete='<div class="info">';
				$view_wall .= $delete.'
					<div class="title">
						<div class="icon"><a href="'.$row_user_id['id'].'/"><img src="'.url_hinh_user_40x40.$row_user_id['avatar'].'.jpg" alt="" /></a></div>
						<div class="name"><a href="'.$row_user_id['id'].'/">'.$row_user_id['name'].'</a></div>
						<div class="date">'.$date.' <a href="#" id="share"><img style="padding:0 5px" src="images/public_icon.jpg" alt="share" /></a></div>
					</div>
					<div class="content">'.$row_wall_info['content'].'</div>
					<div class="view_photo">'.$photo_view.'<div style="clear:both; height:1px"></div></div>
					<div class="action"><a href="javascript:;" class="like like_'.$row_wall_info['id'].'">'.$like.'</a> &nbsp; <a href="javascript:;" class="binhluan '.$row_wall_info['id'].'">Bình luận</a><span style="color:#999; padding-left:10px">'.$total_like.'</span></div>
				';
				$comment = $tc->view_comment($row_wall_info['id']); 
				if(mysql_num_rows($comment)==1){
					$row_comment = mysql_fetch_array($comment);
					$m_comment = explode(' |-| ',$row_comment['comment']);
					$m_user_id = explode(' |-| ',$row_comment['user_id']);
					$m_date_create = explode(' |-| ',$row_comment['date_create']);
					$view_wall .= '<div id="ajax_wall_cm'.$row_wall_info['id'].'"></div>';
					for($i=count($m_comment)-1; $i>0; $i--){
						$user_comment = $tc->user_info($m_user_id[$i]);
						$user_comment = mysql_fetch_array($user_comment);
						$view_wall .= '<div class="comment"><div class="comment_img"><a href="'.$m_user_id[$i].'/"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt=""></a></div><div class="comment_cm"><a href="'.$m_user_id[$i].'/"><strong>'.$user_comment['name'].'</strong></a> '.$m_comment[$i].'<div class="date">'.$tc->wall_datetime($m_date_create[$i]).'</div></div><div style="clear:both; height:1px"></div></div>';
					}
				}
				if(@$idUser) $wall_comment = '<div class="show_cm show_cm'.$row_wall_info['id'].'"><div class="comment"><div class="comment_img"><a href="#"><img src="'.$avatar.'" alt=""> </a></div><div class="comment_cm"><input type="text" name="comment" value="" id="comment'.$row_wall_info['id'].'" class="frmcomment" /></div><div style="clear:both; height:1px"></div></div></div>';
				$view_wall .= $wall_comment.'</div>';
			}
		}
	}
	echo $view_wall;
}